{extend name="base" /}
{block name="body"}
<link rel="stylesheet" href="/static/dist/basic.min.css" />
<link rel="stylesheet" href="/static/dist/dropzone.min.css" />

<div  style="width: 1000px;height: 1600px">
    <div class="layui-card-body">
        <form action="{:request()->url()}" class="layui-form" method="post">
            <div class="layui-form-item">
                <label class="layui-form-label">内容</label>
                <div class="layui-input-block">
                    <input name="content" hidden="hidden" value="{$data.content | default = ''}">
                    <script id="editor" type="text/plain" ></script>
                </div>
            </div>
            <input name="isedit" value="{:input('isedit')}" hidden="hidden">

            <textarea hidden="hidden" id="htmlcon">{$data.content | default = ''}</textarea>
        </form>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-filter="i" id="sub" >保存</button>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript" src="/static/js/jquery.min.js"></script>
<script src="/static/js/clipboard.js"></script>
<script src="/static/dist/dropzone.min.js"></script>
<script type="text/javascript" charset="utf-8" src="/static/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="/static/ueditor/ueditor.all.js"> </script >

{/block}

{block name="js"}
<script>
    $('#sub').click(function(){
        $('input[name="content"]').val(ue.getContent());
        if($('input[name="path"]').val() == ''){
            layer.open({
                content: '主图必须上传' //这里content是一个普通的String
            });
            return;
        }

        if($('input[name="path"]').val() == ''){
            layer.open({
                content: '主图必须上传' //这里content是一个普通的String
            });
            return;
        }

        var data = $('form').serializeJson();
        $.ajax({
            url:'content_add',
            data: data,
            method:'post',
            success:function(res){
                layer.open({
                    content: res.msg, //这里content是一个普通的String
                    end: function(){ //此处用于演示
                        if(res.code == 1){
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.location.reload();//刷新父页面，注意一定要在关闭当前iframe层之前执行刷新
                            parent.layer.close(index); //再执行关闭
                        }
                    }
                });


            }
        });
    })

    var ue = UE.getEditor( 'editor', {

        autoHeightEnabled: true,

        autoFloatEnabled: true,

        initialFrameWidth: 580,

        initialFrameHeight:400,
    });

    ue.ready(function() {
        var htmlcon=$('#htmlcon').text();
        ue.setContent(htmlcon);
    });
</script>
{/block}
